package com.lal.springboot.service;

import com.lal.sdk.LalServerClient;
import com.lal.sdk.model.LalResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LalServerService {

    @Autowired
    private LalServerClient lalServerClient;

    public LalResponse startPullStream(String streamName, String rtspUrl) {
        return lalServerClient.startPullStream(streamName, rtspUrl);
    }

    public LalResponse stopPullStream(String streamName) {
        return lalServerClient.stopPullStream(streamName);
    }

    public LalResponse getStreamStatus(String streamName) {
        return lalServerClient.getStreamStatus(streamName);
    }

    public String getFlvUrl(String streamName) {
        return lalServerClient.getFlvUrl(streamName);
    }

    public String getHlsUrl(String streamName) {
        return lalServerClient.getHlsUrl(streamName);
    }

    public String getWebRtcUrl(String streamName) {
        return lalServerClient.getWebRtcUrl(streamName);
    }

    public String getSecureFlvUrl(String streamName, String clientIp) {
        return lalServerClient.getSecureFlvUrl(streamName, clientIp);
    }

    public String getSecureHlsUrl(String streamName, String clientIp) {
        return lalServerClient.getSecureHlsUrl(streamName, clientIp);
    }

    public String getSecureWebRtcUrl(String streamName, String clientIp) {
        return lalServerClient.getSecureWebRtcUrl(streamName, clientIp);
    }

    public boolean validateStreamAccess(String token, String streamName, String clientIp) {
        return lalServerClient.validateStreamAccess(token, streamName, clientIp);
    }

    public void revokeStreamAccess(String token) {
        lalServerClient.revokeStreamAccess(token);
    }

    public void cleanupExpiredSessions() {
        lalServerClient.cleanupExpiredSessions();
    }

    public String getOriginalStreamUrl(String streamName, String format) {
        switch (format.toLowerCase()) {
            case "flv":
                return getFlvUrl(streamName);
            case "hls":
                return getHlsUrl(streamName);
            case "webrtc":
                return getWebRtcUrl(streamName);
            default:
                return null;
        }
    }
}